package com.lovemanai.action.book;

import com.lovemanai.service.BookService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 该Action映射到/book/get-books.action
 * @author lovemanai
 *
 */
public class GetBooksAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	private String[] books;

	public String[] getBooks() {
		return books;
	}

	public void setBooks(String[] books) {
		this.books = books;
	}
	
	public String execute() throws Exception {
		ActionContext act = ActionContext.getContext();
		String username = (String) act.get("username");
		
		if(username != null && username.equals("jerry")) {
			BookService bs = new BookService();
			setBooks(bs.getAllBooks());
			return SUCCESS;
		}
		return LOGIN;
	}
}
